class SmsEmailsDailyStat < ActiveRecord::Base
  def self.today_stat
    find_or_create_by_stated_on(Date.today)
  end
  
  def add_sms_count!(args = { :sms_count => 1})
    args[:sms_count] ||= 1
    self.sms_count += args[:sms_count]
    save(false)
  end
  
  def users_count!
    self.users_count = User.all.size
    save(false)
  end
  
  def sms_count!
    self.sms_count = UserSmsEmailsDailyStat.sum(:sms_count, :conditions => ['stated_on = ? ',stated_on])
    save(false)
  end
  
  def emails_count!
    self.emails_count = UserSmsEmailsDailyStat.sum(:emails_count, :conditions => ['stated_on = ? ',stated_on])
    save(false)
  end
  
  def add_emails_count!(args = {:emails_count => 1})
    args[:emails_count] ||= 1
    self.emails_count += args[:emails_count]
    save(false)
  end
  
  def stat!
    users_count!
    sms_count!
    emails_count!
  end
end
